class elevator{
	private int curFloor;
	private int tarFloor;
	public String direction;
	private int[] stay = new int[7];
	private int id;
	public elevator(int x){
		id = x;
		curFloor = 1;
		tarFloor = 1;
		direction = "stay";
		for(int i=1;i<7;i++) stay[i] = -1;
	}
	public void setCurFloor(int value){
		this.curFloor = value;
	}
	public void setTarFloor(int value){
		this.tarFloor = value;
		if(tarFloor>curFloor) direction = "up";
		else direction = "down";
		System.out.println("targerFloor: "+value+"\ncurFloor: "+curFloor+"\n dir is:"+direction);
	}
	public void setStay(int index){
		this.stay[index] = 1;
	}
	public int getCurFloor(){
		return curFloor;
	}
	public int getTarFloor(){
		return tarFloor;
	}
	public boolean isRun(){
		if(this.direction=="stay") return false;
		else return true; 
	}
	private void sleep(int milsec){
		try
		{
			Thread.sleep(milsec);
		}
		catch(Exception e){
			System.out.println("sleep error!");
		}
	}
	public void move(){
		System.out.println("move!");
		if(tarFloor==curFloor || direction == "stay") return;
		System.out.println("move????");
		int s;
		if(direction == "up"){
			s = tarFloor-curFloor;
			while(s-->0){
				
				if(stay[curFloor] == 1) {
					System.out.println("waitting for someone");
					sleep(8000);
					stay[curFloor++] = -1;
					GUI.move(this.id,curFloor);
				}
				else {
					//sleep(2000);
					curFloor++;
					GUI.move(this.id,curFloor);
				}
				System.out.println(curFloor+"  is arriving!");
			}
		}
		else if(direction == "down"){
			s = curFloor-tarFloor;
			while(s-->0){
				
				if(stay[curFloor] == 1) {
					System.out.println("waitting for someone");
					sleep(8000);
					stay[curFloor--] = -1;
					GUI.move(this.id,curFloor);
				}
				else {
					//sleep(2000);
					curFloor--;
					GUI.move(this.id,curFloor);
				}
				System.out.println(curFloor+"  is arriving!");
			}
		}
		this.tarFloor = curFloor;
		direction = "stay";
	}


}